package com.adinnet.api.appVersion.controller;

import com.adinnet.api.appVersion.model.AppVersion;
import com.adinnet.api.appVersion.model.vo.AppVersionResp;
import com.adinnet.api.appVersion.service.AppVersionService;
import com.adinnet.core.JsonResult;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * app版本管理 前端控制器
 * </p>
 *
 * @author liukp
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/api/appVersion")
public class AppVersionController extends ApiController {

    @Autowired
    private AppVersionService appVersionService;

    /**
     * 2021-01-11 app要求版本更新返回只返回最新的版本
     * 如果app传过来的版本，不在后台数据库里，默认不更新
     * 如果最新的版本和当前的版本之间的版本有强制更新的版本，那么app不管最新的app版本是否强制更新，都需要强制更新
     * 获取APP最新版本
     * @return
     */
    @GetMapping("getAppVersion")
    public JsonResult getAppVersion(@RequestParam(value = "appType") Integer appType,@RequestParam(value = "version") String version) {
        try {
            AppVersionResp appVersion = appVersionService.getAppVersion(appType,version);
            return JsonResult.ok().put("data",appVersion);
        }catch (Exception e){
            return JsonResult.error("操作失败");
        }
    }
}
